package com.irdstudio.efp.rule.service.impl;

import java.util.List;
import java.util.Objects;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.irdstudio.basic.framework.core.base.FrameworkService;
import com.irdstudio.efp.rule.service.dao.TaxWithholdRemitCorpDao;
import com.irdstudio.efp.rule.service.domain.TaxWithholdRemitCorp;
import com.irdstudio.efp.rule.service.facade.TaxWithholdRemitCorpService;
import com.irdstudio.efp.rule.service.vo.TaxWithholdRemitCorpVO;


/**
 * Service Impl: 代扣代缴单位信息服务实现
 * @author ligm
 * @date 2019-04-29 
 */
@Service("taxWithholdRemitCorpService")
public class TaxWithholdRemitCorpServiceImpl implements TaxWithholdRemitCorpService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(TaxWithholdRemitCorpServiceImpl.class);

	@Autowired
	private TaxWithholdRemitCorpDao taxWithholdRemitCorpDao;

   	/**
	 * 新增数据 
     * @param inTaxWithholdRemitCorpVo
     * @return 
	 */
	public int insertTaxWithholdRemitCorp(TaxWithholdRemitCorpVO inTaxWithholdRemitCorpVo) {
		logger.debug("当前新增数据为:"+ inTaxWithholdRemitCorpVo.toString());
		int num = 0;
		try {
			TaxWithholdRemitCorp taxWithholdRemitCorp = new TaxWithholdRemitCorp();
			beanCopy(inTaxWithholdRemitCorpVo, taxWithholdRemitCorp);
			num = taxWithholdRemitCorpDao.insertTaxWithholdRemitCorp(taxWithholdRemitCorp);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

    /**
	 * 根据主键删除信息 
	 * @param inTaxWithholdRemitCorpVo
 	 * @return
	 */
	public int deleteByPk(TaxWithholdRemitCorpVO inTaxWithholdRemitCorpVo) {
		logger.debug("当前删除数据条件为:"+ inTaxWithholdRemitCorpVo);
		int num = 0;
		try {
			TaxWithholdRemitCorp taxWithholdRemitCorp = new TaxWithholdRemitCorp();
			beanCopy(inTaxWithholdRemitCorpVo, taxWithholdRemitCorp);
			num = taxWithholdRemitCorpDao.deleteByPk(taxWithholdRemitCorp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inTaxWithholdRemitCorpVo +"删除的数据条数为"+ num);
		return num;
	}


    /**
	 * 根据主键更新信息 
	 * @param inTaxWithholdRemitCorpVo
	 * @return 
	 */  
	public int updateByPk(TaxWithholdRemitCorpVO inTaxWithholdRemitCorpVo) {
		logger.debug("当前修改数据为:"+ inTaxWithholdRemitCorpVo.toString());
		int num = 0;
		try {
			TaxWithholdRemitCorp taxWithholdRemitCorp = new TaxWithholdRemitCorp();
			beanCopy(inTaxWithholdRemitCorpVo, taxWithholdRemitCorp);
			num = taxWithholdRemitCorpDao.updateByPk(taxWithholdRemitCorp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inTaxWithholdRemitCorpVo +"修改的数据条数为"+ num);
		return num;
	}
	
    /**
	 * 根据主键查询详情 
	 * @param taxWithholdRemitCorp
	 * @return 
	 */
	public TaxWithholdRemitCorpVO queryByPk(TaxWithholdRemitCorpVO inTaxWithholdRemitCorpVo) {
		
		logger.debug("当前查询参数信息为:"+ inTaxWithholdRemitCorpVo);
		try {
			TaxWithholdRemitCorp queryTaxWithholdRemitCorp = new TaxWithholdRemitCorp();
			beanCopy(inTaxWithholdRemitCorpVo, queryTaxWithholdRemitCorp);
			TaxWithholdRemitCorp queryRslTaxWithholdRemitCorp = taxWithholdRemitCorpDao.queryByPk(queryTaxWithholdRemitCorp);
			if (Objects.nonNull(queryRslTaxWithholdRemitCorp)) {
				TaxWithholdRemitCorpVO outTaxWithholdRemitCorpVo = beanCopy(queryRslTaxWithholdRemitCorp, new TaxWithholdRemitCorpVO());
				logger.debug("当前查询结果为:"+ outTaxWithholdRemitCorpVo.toString());
				return outTaxWithholdRemitCorpVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


    /**
	 * 一级数据权限 
	 * @param taxWithholdRemitCorp
	 * @return 
	 */	
	@SuppressWarnings("unchecked")
	public List<TaxWithholdRemitCorpVO> queryAllByLevelOne(TaxWithholdRemitCorpVO taxWithholdRemitCorpVo) {
		logger.debug("查看当前用户对应的数据信息的参数信息为:");
		List<TaxWithholdRemitCorpVO> list = null;
		try {
			List<TaxWithholdRemitCorp> taxWithholdRemitCorps = taxWithholdRemitCorpDao.queryAllByLevelOneByPage(taxWithholdRemitCorpVo);
			logger.debug("查看当前用户对应的数据信息的结果集数量为:"+ taxWithholdRemitCorps.size());
			pageSet(taxWithholdRemitCorps, taxWithholdRemitCorpVo);
			list = (List<TaxWithholdRemitCorpVO>) beansCopy(taxWithholdRemitCorps, TaxWithholdRemitCorpVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


    /**
	 * 二级数据权限 
	 * @param taxWithholdRemitCorp
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<TaxWithholdRemitCorpVO> queryAllByLevelTwo(TaxWithholdRemitCorpVO taxWithholdRemitCorpVo) {
		logger.debug("查看当前用户及所属机构对应的数据信息的参数信息为:");
		List<TaxWithholdRemitCorp> taxWithholdRemitCorps = taxWithholdRemitCorpDao.queryAllByLevelTwoByPage(taxWithholdRemitCorpVo);
		logger.debug("查看当前用户及所属机构对应的数据信息的结果集数量为:"+taxWithholdRemitCorps.size());
		List<TaxWithholdRemitCorpVO> list = null;
		try {
			pageSet(taxWithholdRemitCorps, taxWithholdRemitCorpVo);
			list = (List<TaxWithholdRemitCorpVO>) beansCopy(taxWithholdRemitCorps, TaxWithholdRemitCorpVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


    /**
	 * 三级数据权限 
	 * @param taxWithholdRemitCorp
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<TaxWithholdRemitCorpVO> queryAllByLevelThree(TaxWithholdRemitCorpVO taxWithholdRemitCorpVo) {
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的参数信息为:");
		List<TaxWithholdRemitCorp> taxWithholdRemitCorps = taxWithholdRemitCorpDao.queryAllByLevelThreeByPage(taxWithholdRemitCorpVo);
		logger.debug("查看当前用户所在机构及下属机构对应的数据信息的结果集数量为:"+ taxWithholdRemitCorps.size());
		List<TaxWithholdRemitCorpVO> list = null;
		try {
			pageSet(taxWithholdRemitCorps, taxWithholdRemitCorpVo);
			list = (List<TaxWithholdRemitCorpVO>) beansCopy(taxWithholdRemitCorps, TaxWithholdRemitCorpVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}

    /**
	 * 四级数据权限  
	 * @param taxWithholdRemitCorp
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<TaxWithholdRemitCorpVO> queryAllByLevelFour(TaxWithholdRemitCorpVO taxWithholdRemitCorpVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<TaxWithholdRemitCorp> taxWithholdRemitCorps = taxWithholdRemitCorpDao.queryAllByLevelFourByPage(taxWithholdRemitCorpVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:"+ taxWithholdRemitCorps.size());
		List<TaxWithholdRemitCorpVO> list = null;
		try {
			pageSet(taxWithholdRemitCorps, taxWithholdRemitCorpVo);
			list = (List<TaxWithholdRemitCorpVO>) beansCopy(taxWithholdRemitCorps, TaxWithholdRemitCorpVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}

    /**
	 * 五级数据权限  
	 * @param taxWithholdRemitCorp
	 * @return 
	 */
	@SuppressWarnings("unchecked")
	public List<TaxWithholdRemitCorpVO> queryAllByLevelFive(TaxWithholdRemitCorpVO taxWithholdRemitCorpVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<TaxWithholdRemitCorp> taxWithholdRemitCorps = taxWithholdRemitCorpDao.queryAllByLevelFiveByPage(taxWithholdRemitCorpVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:"+ taxWithholdRemitCorps.size());
		List<TaxWithholdRemitCorpVO> list = null;
		try {
			pageSet(taxWithholdRemitCorps, taxWithholdRemitCorpVo);
			list = (List<TaxWithholdRemitCorpVO>) beansCopy(taxWithholdRemitCorps, TaxWithholdRemitCorpVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<TaxWithholdRemitCorpVO> queryAllByLmtApplySeq(TaxWithholdRemitCorpVO taxWithholdRemitCorpVo) {
		logger.debug("【预留，便于后续自定义 】信息的参数信息为:");
		List<TaxWithholdRemitCorp> taxWithholdRemitCorps = taxWithholdRemitCorpDao.queryAllByLmtApplySeq(taxWithholdRemitCorpVo);
		logger.debug("【预留，便于后续自定义 】信息的结果集数量为:"+ taxWithholdRemitCorps.size());
		List<TaxWithholdRemitCorpVO> list = null;
		try {
			pageSet(taxWithholdRemitCorps, taxWithholdRemitCorpVo);
			list = (List<TaxWithholdRemitCorpVO>) beansCopy(taxWithholdRemitCorps, TaxWithholdRemitCorpVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	}
	/**
	 * TODO <br>
	 * 0.2: weijj:2019年5月29日 下午2:35:05:TODO <br>
	 * @author  weijj
	 * @since 2019年5月29日 下午2:35:05
	 * @date 2019年5月29日 下午2:35:05
	 * @version 0.1 初始为0.1,后续变更则修改
	 */
	@Override
	public TaxWithholdRemitCorpVO queryTaxWithholdRemitCorpByCrdtAppFlowNoAndwthldngTaxpyNo(
			TaxWithholdRemitCorpVO taxWithholdRemitCorpVo) {
		// TODO Auto-generated method stub
		logger.debug("当前查询参数信息为:"+ taxWithholdRemitCorpVo);
		try {
			TaxWithholdRemitCorp queryTaxWithholdRemitCorp = new TaxWithholdRemitCorp();
			beanCopy(taxWithholdRemitCorpVo, queryTaxWithholdRemitCorp);
			TaxWithholdRemitCorp queryRslTaxWithholdRemitCorp = taxWithholdRemitCorpDao.queryTaxWithholdRemitCorpByCrdtAppFlowNoAndwthldngTaxpyNo(queryTaxWithholdRemitCorp);
			if (Objects.nonNull(queryRslTaxWithholdRemitCorp)) {
				TaxWithholdRemitCorpVO outTaxWithholdRemitCorpVo = beanCopy(queryRslTaxWithholdRemitCorp, new TaxWithholdRemitCorpVO());
				logger.debug("当前查询结果为:"+ outTaxWithholdRemitCorpVo.toString());
				return outTaxWithholdRemitCorpVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	@Override
	public TaxWithholdRemitCorpVO queryWthldngCorpNm(TaxWithholdRemitCorpVO taxWithholdRemitCorpVO) {
		logger.debug("当前查询参数信息为:"+ taxWithholdRemitCorpVO);
		try {
			TaxWithholdRemitCorp queryTaxWithholdRemitCorp = new TaxWithholdRemitCorp();
			beanCopy(taxWithholdRemitCorpVO, queryTaxWithholdRemitCorp);
			TaxWithholdRemitCorp queryRslTaxWithholdRemitCorp = taxWithholdRemitCorpDao.queryWthldngCorpNm(queryTaxWithholdRemitCorp);
			if (Objects.nonNull(queryRslTaxWithholdRemitCorp)) {
				TaxWithholdRemitCorpVO outTaxWithholdRemitCorpVo = beanCopy(queryRslTaxWithholdRemitCorp, new TaxWithholdRemitCorpVO());
				logger.debug("当前查询结果为:"+ outTaxWithholdRemitCorpVo.toString());
				return outTaxWithholdRemitCorpVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}

	@Override
	public TaxWithholdRemitCorpVO queryWthldngCorpNm(String crdtAppFlowNo) {
		logger.debug("通过授信申请流水号查询代扣代缴单位信息开始，参数为："+ crdtAppFlowNo);
		try {
			TaxWithholdRemitCorp queryRslTaxWithholdRemitCorp = taxWithholdRemitCorpDao.queryWthldngCorpName(crdtAppFlowNo);
			if (Objects.nonNull(queryRslTaxWithholdRemitCorp)) {
				TaxWithholdRemitCorpVO outTaxWithholdRemitCorpVo = beanCopy(queryRslTaxWithholdRemitCorp, new TaxWithholdRemitCorpVO());
				logger.debug("通过授信申请流水号查询查询结果为:"+ outTaxWithholdRemitCorpVo.toString());
				return outTaxWithholdRemitCorpVo;
			} else {
				logger.debug("通过授信申请流水号查询查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("通过授信申请流水号查询数据发生异常!", e);
		}
		return null;
	}
}
